/**
  ******************************************************************************
  * @file    common.c
  * @author  software Team
  * @brief   This file provides all the common functions.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2020 Hyseim. Co., Ltd.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "common.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

// common delay function;
// for DV case, m should be set to less than 100;
// for FPGA case, m could be set to more than 100;
void mdelay(uint32_t m){
    volatile int n , i;
    n = m;
    while(n>0){
        n--;
    #ifndef PLL_CLK_250M
        for(i = 100;i>0;i--);
    #else
        for(i = 200;i>0;i--);
    #endif
    }
}

// us delay @ SoC_clk=200MHz
void udelay(int m){
    volatile int n , i;
    n = m;
    while(n>0){
        n--;
    #ifndef PLL_CLK_250M
        for(i = 44;i>0;i--);
    #else
        for(i = 22;i>0;i--);
    #endif
    }
}

//TODO uint32_t HAL_GetTick(void);
uint32_t HAL_GetTick(void)
{
    return 0;
}


void jump_and_start(int addr)
{
    unsigned int *r;
    void (*jump_start)();

    r = (unsigned int *)(addr);

    jump_start = (void (*) ())(r);

    jump_start();

    return;
}


